package sf.r2dbc.sql;

import io.r2dbc.spi.Connection;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import sf.common.wrapper.Page;
import sf.database.jdbc.sql.PageStrategy;
import sf.database.jdbc.sql.SQLParameter;

import java.util.List;
import java.util.Map;
import java.util.function.Function;

public interface R2dbcCrudSqlInf {
    Flux<Map<String, Object>> select(Connection connection, String sql, List<SQLParameter> paras);

    <T> Mono<T> selectOne(Connection connection, Class<T> beanClass, String sql, List<SQLParameter> parameters);

    <T> Flux<T> selectList(Connection connection, Class<T> beanClass, long start, int limit, String sql, List<SQLParameter> parameters);

    <T> Flux<T> selectList(Connection connection, Class<T> beanClass, String sql, List<SQLParameter> parameters);

    <T> Mono<Page<T>> selectPage(Connection conn, long start, int limit, Class<T> beanClass, String sql,
                                 Object... parameters);

    <T> Mono<Page<T>> selectPageRaw(Connection conn, long start, int limit, Class<T> beanClass, String countSql, Object[] countParas, String listSql, Object[] listParas);

    <T> Mono<Page<T>> selectPageRaw(Connection conn, long start, int limit, Class<T> beanClass, String countSql, Object[] countParas, String listSql, Object[] listParas, PageStrategy strategy);

    <T> Flux<T> selectResult(Connection conn, R2dbcResultSetCallback<T> callback, String sql, Object... parameters);

    Mono<Integer> insert(Connection connection, List<String> pkeys, Map<String, Object> keyValues, String sql, List<SQLParameter> parameters);

    Mono<Integer> execute(Connection connection, String sql, List<SQLParameter> paras);

    Flux<Map<String, Object>> select(Connection connection, String sql, Object... parameters);

    <T> Mono<T> selectOne(Connection connection, Class<T> beanClass, String sql, Object... parameters);

    <T> Flux<T> selectList(Connection connection, Class<T> beanClass, long start, int limit, String sql, Object... parameters);

    <T> Flux<T> selectList(Connection connection, Class<T> beanClass, String sql, Object... parameters);

    <T> T execute(Connection con, Function<Connection, T> action);

    Mono<Integer> execute(Connection connection, String sql, Object... parameters);

    Mono<Integer> execute(Connection connection, String sql);

    Mono<Integer> insertFast(Connection conn,
                             String sql, Object... parameters);

    Mono<Integer> insert(Connection conn, List<String> pkeys, Map<String, Object> keyValues, String sql, Object... parameters);

    Mono<Integer> execute(Connection conn, String sql, Object[] parameters, boolean insertFast,
                          List<String> pkeys, Map<String, Object> keyValues);

    Flux<Integer> executeBatch(Connection conn, String sql, List<Object[]> parameters);

    Flux<Integer> executeBatch(Connection conn, String sql, List<Object[]> parameters, boolean insertFast,
                               List<String> pkeys, List<Map<String, Object>> keyValues);
}
